package com.jhc.auth.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import com.jhc.common.core.base.BaseController;
import com.jhc.common.core.web.domain.AjaxResult;
import com.jhc.api.auth.form.LoginBody;
import com.jhc.api.auth.form.RegisterBody;
import com.jhc.api.auth.service.TokenService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * token 控制
 *
 */
@RestController
public class TokenController extends BaseController<TokenService> {



    @PostMapping("login")
    public SaTokenInfo login(@RequestBody LoginBody form) {
        return service.login(form);
    }

    @PostMapping("logout")
    public AjaxResult logout() {
        StpUtil.logout();
        return success();
    }

    @PostMapping("refresh")
    public AjaxResult refresh() {
        // TODO 修改逻辑
        return success(StpUtil.isLogin());
    }

    @PostMapping("register")
    public AjaxResult register(@RequestBody RegisterBody registerBody) {
        // 用户注册
        service.register(registerBody);
        return success();
    }
}
